using System;
using System.Collections.Generic;
using Android.Widget;

namespace Granite.Axml
{
	public class TextViewTextBinding : BindingBase
	{
		readonly TextView m_Target;

		public TextViewTextBinding(TextView target, object source, string bindingExpression, BindingMode? mode = null)
			: base(target, new BindingFragment(source, bindingExpression))
		{

			m_Target = target;

			if ((mode == null && target is TextView) || mode == BindingMode.TwoWay)
				m_Target.AfterTextChanged += Target_AfterTextChanged;
			Activate();
		}

		private void Target_AfterTextChanged(object sender, Android.Text.AfterTextChangedEventArgs e)
		{
			WriteValue(m_Target.Text);
		}

		protected override void OnValueChanged(object value)
		{
			m_Target.Text = (string)value;
		}
	}
}


